package com.wufeng.model.SpringBootModel.controller;

import java.util.List;

import com.wufeng.model.SpringBootModel.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wufeng.model.SpringBootModel.model.User;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api(value = "PageController", description = "用户登录登出接口")
@RestController
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	private UserService userService;

	@ApiOperation(value = "展示所有用户" ,  notes="展示所有用户")
	@RequestMapping(value = "/list")
	public List<User> findList(){
		return userService.findAll();
	}

	//@PathVariable 获取url中的数据  例：localhost:8080/user/list/jack
	@GetMapping(value = "/listOne/{id}")
	@ApiOperation(value = "根据用户id查询" ,  notes="根据用户id查询")
	@ApiImplicitParam(name = "id", value = "用户ID", paramType = "path", required = true, dataType = "long")
	public User findByUserName(@PathVariable("id") long id) {
		return userService.findById(id);
	}

	//@RequestParam 获取请求参数的值  例：localhost:8080/hello?id=1000
	@GetMapping(value = "/listOne")
	public User findById(@RequestParam("userName") String userName) {
		return userService.findByName(userName);
	}

}
